<template>
  <div>
    <el-card>
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="tab != '数据分析'"
        label-width="68px"
      >
        <el-form-item label="家长姓名" prop="userName">
          <el-input
            v-model="params.userName"
            placeholder="请输入家长姓名"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="家长昵称" prop="nickName">
          <el-input
            v-model="params.nickName"
            placeholder="请输入家长昵称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
          <el-button
            type="danger"
            size="mini"
            v-show="tab == '未缴费信息' && status == 0 && payType=='1'"
            @click="handleSend"
            >提醒缴费</el-button
          >
        </el-form-item>
      </el-form>
      <div v-show="tab == '数据分析'" class="title">本次缴费数据分析</div>
    </el-card>
    <el-card>
      <el-tabs @tab-click="handleClick">
        <el-tab-pane label="已缴费信息"
          ><el-table v-loading="loading" :data="pdList">
            <el-table-column
              label="序号"
              type="index"
              :index="table_index"
              width="50"
              align="center"
            >
            </el-table-column>
            <el-table-column
              label="头像"
              align="center"
              prop="avatar"
              width="100"
            >
              <template slot-scope="scope">
                <image-preview
                  :src="scope.row.sysUser.avatar"
                  :width="50"
                  :height="50"
                />
              </template>
            </el-table-column>
            <el-table-column
              label="家长姓名"
              align="center"
              prop="sysUser.userName"
            />
            <el-table-column
              label="家长昵称"
              align="center"
              prop="sysUser.nickName"
            />
            <el-table-column
              label="家长电话"
              align="center"
              prop="sysUser.phonenumber"
            />
            <el-table-column
              label="家长邮箱"
              align="center"
              prop="sysUser.email"
            /><el-table-column
              label="缴费时间"
              align="center"
              prop="createTime"
            /><el-table-column label="孩子班级" align="center" prop="remark" />
          </el-table>
          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />缴费记录
        </el-tab-pane>
        <el-tab-pane label="未缴费信息"
          ><el-table v-loading="loading" :data="noPdList">
            <el-table-column
              label="序号"
              type="index"
              :index="table_index"
              width="50"
              align="center"
            >
            </el-table-column>
            <el-table-column
              label="头像"
              align="center"
              prop="avatar"
              width="100"
            >
              <template slot-scope="scope">
                <image-preview
                  :src="scope.row.sysUser.avatar"
                  :width="50"
                  :height="50"
                />
              </template>
            </el-table-column>
            <el-table-column
              label="家长姓名"
              align="center"
              prop="sysUser.userName"
            />
            <el-table-column
              label="家长昵称"
              align="center"
              prop="sysUser.nickName"
            />
            <el-table-column
              label="家长电话"
              align="center"
              prop="sysUser.phonenumber"
            />
            <el-table-column
              label="家长邮箱"
              align="center"
              prop="sysUser.email"
            /><el-table-column
              label="缴费时间"
              align="center"
              prop="createTime"
            /><el-table-column label="孩子班级" align="center" prop="remark" />
          </el-table>
          <pagination
            v-show="noTotal > 0"
            :total="noTotal"
            :page.sync="noQueryParams.pageNum"
            :limit.sync="noQueryParams.pageSize"
            @pagination="getList"
          />未缴费人员</el-tab-pane
        >
        <el-tab-pane label="数据分析">数据分析</el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import { listPd } from "@/api/money/pd";
import {getPay} from "@/api/money/pay"
import { addPdMessage } from "@/api/message/message";
export default {
  name: "Detail",
  data() {
    return {
      status: undefined,
      tab: "已缴费信息",
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      noTotal: 0,
      // 缴费表格数据
      pdList: [],
      noPdList: [],
      // 显示搜索条件
      showSearch: true,
      params: {
        userName: undefined,
        nickName: undefined,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        payId: undefined,
        status: 1,
        userName: undefined,
        nickName: undefined,
      },
      noQueryParams: {
        pageNum: 1,
        pageSize: 10,
        payId: undefined,
        status: 0,
        userName: undefined,
        nickName: undefined,
      },
      payType:'0'
    };
  },
  created() {
    this.queryParams.payId = this.$route.params && this.$route.params.payId;
    this.noQueryParams.payId = this.$route.params && this.$route.params.payId;
    getPay(this.queryParams.payId).then((response)=>{
      if(response.data.payType=='2'){
        this.payType='1'
      }
    })
    this.getList();
  },
  methods: {
    getList() {
      listPd(this.queryParams).then((response) => {
        this.pdList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      setTimeout(() => {
        listPd(this.noQueryParams).then((response) => {
          this.noPdList = response.rows;
          this.noTotal = response.total;
          this.loading = false;
          if (this.noTotal != 0) {
            this.status = this.noPdList[0].pay.progressStatus;
          }
        });
      }, 3000);
    },
    //序号换页问题
    table_index(index) {
      return (
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if (this.tab == "已缴费信息") {
        this.queryParams.pageNum = 1;
        if (this.params.userName == "") {
          this.params.userName = undefined;
        }
        if (this.params.nickName == "") {
          this.params.nickName = undefined;
        }
        this.queryParams.userName = this.params.userName;
        this.queryParams.nickName = this.params.nickName;
        listPd(this.queryParams).then((response) => {
          this.pdList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      } else {
        if (this.params.userName == "") {
          this.params.userName = undefined;
        }
        if (this.params.nickName == "") {
          this.params.nickName = undefined;
        }
        this.noQueryParams.pageNum = 1;
        this.noQueryParams.userName = this.params.userName;
        this.noQueryParams.nickName = this.params.nickName;
        // console.log(this.noQueryParams);
        listPd(this.noQueryParams).then((response) => {
          this.noPdList = response.rows;
          this.noTotal = response.total;
          this.loading = false;
        });
      }
    },
    /* 菜单重置 */
    resetQuery() {
      this.resetForm("queryForm");
      this.params.userName = undefined;
      this.params.nickName = undefined;
      if (this.tab == "已缴费信息") {
        this.queryParams.pageNum = 1;
        this.queryParams.userName = undefined;
        this.queryParams.nickName = undefined;
        listPd(this.queryParams).then((response) => {
          this.pdList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      } else {
        this.noQueryParams.pageNum = 1;
        this.noQueryParams.userName = undefined;
        this.noQueryParams.nickName = undefined;
        listPd(this.noQueryParams).then((response) => {
          this.noPdList = response.rows;
          this.noTotal = response.total;
          this.loading = false;
        });
      }
    },
    handleClick(tab) {
      this.tab = tab.label;
    },
    handleSend() {
      this.$modal.confirm("是否提醒缴费?").then(() => {
        this.loading = true;
        return addPdMessage(this.queryParams.payId).then((res) => {
          if (res.code != 200) {
            this.$modal.msgError("系统异常,请联系管理员");
          } else {
            this.$modal.msgSuccess("提醒成功");
            this.loading = false;
          }
        });
      });
    },
  },
};
</script>

<style lang="less">
.tabletitle-timeline {
  line-height: 18px !important;
}
.el-card.is-always-shadow {
  margin: 20px;
}
.title {
  text-align: center;
  display: block;
  font-weight: bold;
}
</style>